<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 10171225
  Date: 2016/4/7
  Time: 10:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>"/>
    <title>页头</title>
    <link rel="stylesheet" href="static/themes/bootstrap/easyui.css">
    <link rel="stylesheet" href="static/css/base.css">
    <script src="static/javascript/jquery-1.11.3.min.js"></script>
    <script src="static/javascript/jquery.easyui.min.js"></script>
    <script src="static/javascript/utils.js"></script>
    <script src="static/javascript/base.js"></script>

    <link rel="stylesheet" href="plugins/bootstrap-3.3.5-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="plugins/bootstrap-3.3.5-dist/css/bootstrap-theme.min.css">
    <script src="plugins/bootstrap-3.3.5-dist/js/bootstrap.min.js"></script>

    <script type="text/javascript" language="JavaScript">
        $(document).ready(function(){
            toggleMenu($("#index"));

            function toggleMenu(tag){
                $("#menu-top li").each(function(){
                    $(this).removeClass("current");
                });
                tag.parent("li").addClass("current");
            }

            function loadMainContent(url) {
                obj=$.ajax({url:url,async:false});
                $("#main").html(obj.responseText);
            }

            $("#freeRegister").click(function () {
                $("#main").load("views/register.jsp");
                return false;
            });

            $("#forgetPassword").click(function () {
                $("#main").load("views/forgetPassword.jsp");
                return false;
            });

            $("#chartDes").click(function () {
                toggleMenu($(this));
                loadMainContent("page/chartDes");
            });

            $("#selectNumber").click(function () {
                toggleMenu($(this));
                loadMainContent("page/selectNumber");
            });

            $("#articles").click(function () {
                toggleMenu($(this));
                loadMainContent("page/articles");
            });

            $("#other").click(function () {
                toggleMenu($(this));
                loadMainContent("page/other");
            });

            $("#personalHomePage").click(function () {
                $("#main").load("views/personalHomePage.jsp");
            });

            $("#loginSubmit").click(function () {
                var map = {
                    "用户名": $("#userName"),
                    "密码": $("#userPassword")
                }
                if($.judgeNotNull(map) == false){
                    return false;
                }
                $.ajax({
                    type : 'get',
                    contentType:"application/json;charset=utf-8",
                    url : 'user/loginAction',
                    dataType : 'json',
                    cache: false,
                    timeout: 5000,
                    async: false,
                    data: {
                        "userName": encodeURI($("#userName").val()),
                        "userPassword": encodeURI($("#userPassword").val())
                    },
                    success: function(result){
                        if(result.indexOf("成功") != -1){
                            obj=$.ajax({url:"index",async:false});
                            $("body").html(obj.responseText);
                        } else {
                            alert(result);
                        }
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert("ajax异常，请联系管理员！");
                    }
                });
            });

        });
    </script>

</head>
<body>
<div class="head">
    <c:choose>
        <c:when test="${sessionScope.containsKey('userName')}">
            <div align="right">
                你好，<a id="personalHomePage">${sessionScope.get('userName')}</a>
                &nbsp;<a href="user/logout">退出</a>&nbsp;&nbsp;
            </div>
        </c:when>
        <c:otherwise>
            <div>
                <form>
                    <span>用户名：</span><input type="text" id="userName" name="userName"/>
                    <span>密码：</span><input type="password" id="userPassword" name="userPassword"/>
                    &nbsp;<button name="submit" id="loginSubmit" type="submit">登录</button>
                    &nbsp;<a id="forgetPassword">忘记密码</a>
                    &nbsp;<a id="freeRegister">免费注册</a>
                </form>
            </div>
        </c:otherwise>
    </c:choose>
</div>

<div class="logo">
    <label>Logo</label>
</div>
<div class="menu-top-container">
    <ul id="menu-top">
        <li class="menu-item"><a href="index" id="index">首页</a></li>
        <li class="menu-item"><a id="chartDes">图表说明</a></li>
        <li class="menu-item"><a id="selectNumber">图形选号</a></li>
        <li class="menu-item"><a id="articles">文章</a></li>
        <%--<li class="menu-item"><a id="other">其他</a></li>--%>
    </ul>
</div>
</body>
</html>
